package com.wisemoresystem.seal.action.seal.use;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.service.SealSetService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章停用
 * 
 * @author Administrator
 *
 */
@Controller("ixSealStop")
@Scope("prototype")
@RequestMapping("/ix/seal/set/stop")
public class SealStopAction extends ProjBaseAction {

	@Autowired
	private SealSetService sealService;

	/**
	 * 印章停用列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = sealService.selectSealStopList(
				srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/set/stop/list");
		mv.addObject("list", list);
		return mv;
	}

	/**
	 * 详细信息
	 * 
	 * @param seal_id
	 *            印章id
	 * @return
	 */
	@RequestMapping("/detail")
	public ModelAndView detail(String seal_id) {

		t_seal seal = oc.findObjById(seal_id, t_seal.class);
		t_bank bank = oc.findObjById(WebTools.getCurrentBankId(), t_bank.class);
		t_seal_new seal_new = oc.findObjById(seal.getSeal_new_id(),
				t_seal_new.class);

		ModelAndView mv = new ModelAndView("/jsp/seal/set/stop/detail");
		mv.addObject("seal", seal);
		mv.addObject("bank", bank);
		mv.addObject("seal_new", seal_new);

		// 判断盖章是否在销毁权限之上
		if (sealService.checkIsTop(seal_id))
			mv.addObject("lev", 0);
		return mv;
	}

	/**
	 * 印章停用
	 * 
	 * @param seal_id
	 *            印章id
	 * @param type
	 *            类型
	 * @return
	 */
	@RequestMapping("/do_detail")
	public ModelAndView do_detail(String seal_id, String type) {

		if (sealService.stopSeal(seal_id, type)) {
			logT.logH("停用印章", t_seal.class, seal_id);
			super.setTipMsg("停用成功", Tip.Type.success);
		} else {
			super.setTipMsg("停用失败", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}
